package org.scboy.common.init;

import org.apache.dubbo.config.annotation.DubboReference;
import org.scboy.common.loads.LoadPermission;
import org.scboy.dbms.api.IPermissionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

/**
 * 权限请求的初始化
 */
@Configuration
public class PermissionInit implements ApplicationListener<ApplicationReadyEvent>{

	Log log=LogFactory.get();
	
	@Value("${spring.application.name}")
	String appName;

	@Value("${server.port}")
	int prot;
	
	@DubboReference
	IPermissionManager permissionManager;
	
	@Autowired
	LoadPermission load;
	
	@Override
	public void onApplicationEvent(ApplicationReadyEvent event) {
		log.info("开始初始化权限地址配置");
		permissionManager.updatePermission(load.init(), appName);
	}
}
